package com.mjk.common.tools.encrypt;


import com.mjk.common.tools.logger.BizLogger;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class SHA512Util {

	private SHA512Util(){}

	public static String sha512(String strText) {
		String strResult = null;

		if ((strText != null) && (!strText.isEmpty())) {
			try {
				MessageDigest messageDigest = MessageDigest
						.getInstance("SHA-512");

				messageDigest.update(strText.getBytes());

				byte[] byteBuffer = messageDigest.digest();

				StringBuilder strHexString = new StringBuilder();

                for (byte b : byteBuffer) {
                    String hex = Integer.toHexString(0xFF & b);
                    if (hex.length() == 1) {
                        strHexString.append('0');
                    }
                    strHexString.append(hex);
                }

				strResult = strHexString.toString();
			} catch (NoSuchAlgorithmException e) {
				BizLogger.error(e);
			}
		}
		return strResult;
	}
}